package com.example;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;



public class MyCustomBaseAdapter extends BaseAdapter {
 private static ArrayList<Task> searchArrayList;

 private LayoutInflater mInflater;

 public MyCustomBaseAdapter(Context context, ArrayList<Task> results) {
  searchArrayList = results;
  mInflater = LayoutInflater.from(context);

 }

 public int getCount() {
  return searchArrayList.size();
 }

 public Object getItem(int position) {
  return searchArrayList.get(position);
 }

 public long getItemId(int position) {
  return position;
 }

public View getView(int position, View convertView, ViewGroup parent) {
  ViewHolder holder;
  if (convertView == null) {
   convertView = mInflater.inflate(R.layout.element, null);
   holder = new ViewHolder();

      holder.txtTitle = (TextView) convertView.findViewById(R.id.task_title);
      holder.txtWhere = (TextView) convertView.findViewById(R.id.task_where);
      holder.txtFrom = (TextView) convertView.findViewById(R.id.task_from);
      holder.txtTo = (TextView) convertView.findViewById(R.id.task_to);
      holder.txtdesc = (TextView) convertView.findViewById(R.id.task_des);


   convertView.setTag(holder);
  } else {
   holder = (ViewHolder) convertView.getTag();
  }

  holder.txtTitle.setText(searchArrayList.get(position).title);
  holder.txtWhere.setText(searchArrayList.get(position).where);
  holder.txtFrom.setText(searchArrayList.get(position).from);
  holder.txtTo.setText(searchArrayList.get(position).to);
  holder.txtdesc.setText(searchArrayList.get(position).description);


  return convertView;
 }





 static class ViewHolder {

  TextView txtTitle;
  TextView txtWhere;
  TextView txtFrom;
  TextView txtTo;
  TextView txtdesc;

 }
}
